import React from 'react';
import {Select, Radio} from 'antd/lib/index'

const Option = Select.Option;


export default {
  formatDate(time, patter) {
    if (!time) return "时间显示错误";
    let dt = new Date(time);
    let YY = dt.getFullYear();
    let MM = dt.getMonth() + 1;
    let DD = dt.getDate();
    MM = MM > 9 ? MM : "0" + MM;
    DD = DD > 9 ? DD : "0" + DD;
    //两种搞定不报错的方式
    if (patter && patter.toLowerCase() === "YY-MM-DD") {
      //					第一种方式不够美观
      //return y  + '-' + m + '-' + d;
      return `${YY}-${MM}-${DD}`;
    } else {
      let hh = dt
        .getHours()
        .toString()
        .padStart("2", 0);
      let mm = dt
        .getMinutes()
        .toString()
        .padStart("2", 0);
      let ss = dt
        .getSeconds()
        .toString()
        .padStart("2", 0);
      return `${YY}-${MM}-${DD} ${hh}:${mm}:${ss}`;
    }
  },


  pagination(paginationData, callback, callback2) {
    console.log(paginationData)
    return {
      defaultPageSize: 10,	                                      //默认的每页条数
      defaultCurrent: 1,                                        //默认的当前页数
      current: paginationData.content.page.page,                      //当前页数
      pageSize: paginationData.content.page.size,                        //每页条数
      total: paginationData.content.page.total,                              //数据总数
      showQuickJumper: true,                                    //是否可以快速跳转至某页
      showSizeChanger: true,                                    //是否可以改变 pageSize,可以联合pageSizeOptions使用
      pageSizeOptions: ['10', '20', '50', '100'],	                    //指定每页可以显示多少条
      size: "small",                                            //当为「small」时，是小尺寸分页
      hideOnSinglePage: false,                                   //只有一页时是否隐藏分页器
      disabled: false,                                          //禁用分页
      // simple:true,                                           //当添加该属性时，显示为简单分页
      showTotal: () => {
        return `共${paginationData.content.page.total}条`;
      },

      onChange: (current, size) => {                                    //页码改变的回调，参数是改变后的页码及每页条数 Function(page, pageSize)
        callback(current, size);
      },

      onShowSizeChange: (current, size) => {                   //pageSize 变化的回调  Function(current, size)
        callback(current, size);
      },

      // onShowSizeChange: (current, size) => {                   //pageSize 变化的回调  Function(current, size)
      //   let newPage = this.props.capital.page;
      //   newPage.size = size;
      //   newPage.page = 1;
      //   this.props.dispatch({
      //     type: 'capital/getStatementsList',
      //     payload: {
      //       customerno: values.customerno,
      //       stateno: values.stateno,
      //       status: values.status,
      //       beginTime: beginTime,
      //       endTime: endTime,
      //       minamount: values.minamount,
      //       maxamount: values.maxamount,
      //       creator: values.creator,
      //       page: newPage
      //     }
      //   });
      // },

    };
  },


  // pagination(data, callback) {
  //     return {
  //         current: data.result.page,
  //         pageSize: data.result.page_size,
  //         total: data.result.total_count,
  //         showTotal: () => {
  //             return `共${data.result.total_count}条`
  //         },
  //         showQuickJumper: true,
  //         onChange: (current) => {
  //             callback(current)
  //         },
  //     }
  // },


  getOptionList(data) {
    if (!data) {
      return [];
    }
    let options = [] //[<Option value="0" key="all_key">全部</Option>];
    data.map((item) => options.push(<Option value={item.value} key={item.value}>{item.name}</Option>))
    return options;
  },

  getRadioList(data) {
    if (!data) {
      return [];
    }
    let options = [] //[<Option value="0" key="all_key">全部</Option>];
    data.map((item) => options.push(<Radio value={item.value} key={item.value}>{item.name}</Radio>))
    return options;
  },


  // ETable 行点击通用函数
  updateSelectedItem(selectedRowKeys, selectedRows, selectedIds) {
    if (selectedIds) {
      this.setState({
        selectedRowKeys,
        selectedRows,
        selectedIds,
      })
    } else {
      this.setState({
        selectedRowKeys,
        selectedRows,
      })
    }
  },

};
